using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace S.O.Domain.Medical
{
    /// <summary>
    /// 处方记录实体类
    /// 存储患者的处方信息，包括中药处方和西药处方
    /// </summary>
    [Table("Prescriptions")]
    public class PrescriptionModel : BaseEntity
    {
        /// <summary>
        /// 处方ID（主键）
        /// 格式：PR + 年月日 + 6位序号，如：PR20241201000001
        /// </summary>
        [Key]
        [StringLength(20)]
        [Column("Id")]
        public string Id { get; set; } = string.Empty;

        /// <summary>
        /// 患者ID（外键）
        /// 关联到Patient表
        /// </summary>
        [Required]
        [Column("PatientId")]
        public long PatientId { get; set; }

        /// <summary>
        /// 患者姓名
        /// 冗余字段，便于查询和显示
        /// </summary>
        [Required]
        [StringLength(50)]
        [Column("PatientName")]
        public string PatientName { get; set; } = string.Empty;

        /// <summary>
        /// 处方类型（中药、西药）
        /// </summary>
        [Required]
        [StringLength(10)]
        [Column("PrescriptionType")]
        public string PrescriptionType { get; set; } = string.Empty;

        /// <summary>
        /// 诊断
        /// 医生的诊断结果
        /// </summary>
        [Required]
        [StringLength(500)]
        [Column("Diagnosis")]
        public string Diagnosis { get; set; } = string.Empty;

        /// <summary>
        /// 处方备注
        /// 医生对整个处方的备注说明
        /// </summary>
        [StringLength(1000)]
        [Column("Remark")]
        public string Remark { get; set; } = string.Empty;

        /// <summary>
        /// 医生姓名
        /// 开具处方的医生
        /// </summary>
        [Required]
        [StringLength(50)]
        [Column("Doctor")]
        public string Doctor { get; set; } = string.Empty;

        /// <summary>
        /// 处方状态（已开具、已审核、已发药、已完成）
        /// </summary>
        [Required]
        [StringLength(20)]
        [Column("Status")]
        public string Status { get; set; } = "已开具";

        /// <summary>
        /// 创建时间
        /// </summary>
        [Required]
        [Column("CreateTime")]
        public DateTime CreateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 更新时间
        /// </summary>
        [Required]
        [Column("UpdateTime")]
        public DateTime UpdateTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 是否启用
        /// true-启用，false-禁用
        /// </summary>
        [Required]
        [Column("IsEnable")]
        public bool IsEnable { get; set; } = true;

        /// <summary>
        /// 导航属性：关联的患者信息
        /// </summary>
        [ForeignKey("PatientId")]
        public virtual PatientModel? Patient { get; set; }

        /// <summary>
        /// 导航属性：处方药品列表
        /// </summary>
        public virtual ICollection<PrescriptionMedicineModel> Medicines { get; set; } = new List<PrescriptionMedicineModel>();
    }
}